<?php

class Utility {
	
	
	public function dateDiff($startDate, $endDate) 
{ 
    // Parse dates for conversion 
    $startArry = date_parse($startDate); 
    $endArry = date_parse($endDate); 

    // Convert dates to Julian Days 
    $start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]) - 1; 
    $end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]); 

    // Return difference 
    return round(($end_date - $start_date), 0); 
} 

public static function GetMonth($date) {
		
		$date_year = substr ( $date, 0, 4 );
		$date_month = substr ( $date, 5, 2 );
		$date_day = substr ( $date, 8, 2 );

		if ($date_year == "0000" || $date == "")
			$date = "Any Time";
		else
			$date = date ( "F", @mktime ($date_month) );
		
		return $date;
	}
	
	///////////////////////////////////////////////////   OLD FUNCTIONS   //////////////////////////////////////////////////////////////
	public static function EncryptQueryString($parameter) {
		$hash = md5 ( md5 ( $parameter ) );
		$count = strlen ( $parameter );
		$parameter = $count . $hash . $parameter;
		return $parameter;
	}
	
	public static function DecryptQueryString($parameter) {
		$length = substr ( $parameter, 0, 1 );
		$actual_hash = substr ( $parameter, 1, 32 );
		$parameter = substr ( $parameter, 33 );
		
		if (md5 ( md5 ( $parameter ) ) == $actual_hash)
			return $parameter;
		else
			return null;
	}
	
	public static function GetApplicationPath() {
		$development_env = self::CheckEnv ();
		if ($development_env)
			$path = Constant::APPLICATION_PATH_DEV;
		else
			$path = Constant::APPLICATION_PATH_PROD;
		
		return $path;
	}
	
	public static function GetFrontendPath() {
		$development_env = self::CheckEnv ();
		
		if ($development_env)
			$path = Constant::APPLICATION_FRONTEND_PATH_DEV;
		else
			$path = Constant::APPLICATION_FRONTEND_PATH_PROD;
		
		return $path;
	}
	
	/*public static function GetBackendPath() {
		$development_env = self::CheckEnv ();
		
		if ($development_env)
			$path = Constant::APPLICATION_BACKEND_PATH_DEV;
		else
			$path = Constant::APPLICATION_BACKEND_PATH_PROD;
		
		return $path;
	}*/
	
	private static function CheckEnv() {
		$ip = getenv ( "REMOTE_ADDR" );
		
		if ($ip == "127.0.0.1")
			return true;
		else
			return false;
	}
	
	public static function FormatDate($date) {
		
		$date_year = substr ( $date, 0, 4 );
		$date_month = substr ( $date, 5, 2 );
		$date_day = substr ( $date, 8, 2 );
		
		$time_hr = substr ( $date, 11, 2 );
		$time_min = substr ( $date, 14, 2 );
		$time_sec = substr ( $date, 17, 2 );
		
		//$date=date("D, F j, Y G:i:s T", mktime($time_hr,$time_min,$time_sec,$date_month,$date_day,$date_year));
		if ($date_year == "0000" || $date == "")
			$date = "Any Time";
		else
			$date = date ( "F j, Y", @mktime ( $time_hr, $time_min, $time_sec, $date_month, $date_day, $date_year ) );
		
		return $date;
	}
	
}

?>